package com.qinyunkj.searchchatserver.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qinyunkj.searchchatserver.mapper.SysConfigMapper;
import com.qinyunkj.searchchatserver.model.entity.SysConfig;
import com.qinyunkj.searchchatserver.service.SysConfigService;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

@Service
public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig> implements SysConfigService {

    @Override
    @Cacheable(value = "sys_config", key = "#key")
    public String getConfigValue(String key) {
        SysConfig config = lambdaQuery()
                .eq(SysConfig::getConfigKey, key)
                .one();
        return config != null ? config.getConfigValue() : null;
    }

    @Override
    @CacheEvict(value = "sys_config", key = "#key")
    public void updateConfig(String key, String value) {
        lambdaUpdate()
                .eq(SysConfig::getConfigKey, key)
                .set(SysConfig::getConfigValue, value)
                .update();
    }
} 